package com.exam.service.impls;

import com.exam.domain.Field;
import com.exam.domain.KnowledgePoint;
import com.exam.domain.Question;
import com.exam.domain.QuestionType;
import com.exam.mapper.*;
import com.exam.service.interfaces.QuestionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by jly on 2017/2/13.
 */
@Service("questionService")
public class QuestionServiceImpl implements QuestionService {
    @Resource
    private QuestionMapper questionMapper;
    @Resource
    private FieldMapper fieldMapper;
    @Resource
    private KnowledgePointMapper knowledgePointMapper;
    @Resource
    private QuestionTypeMapper questionTypeMapper;
    @Resource
    private StrategiesMapper strategiesMapper;

    /**
     * 查询所有科目
     *
     * @return: 返回数据库科目表所有内容
     * @Since: 2017-2-13
     * @author: jly
     * */
    @Override
    public List<Field> queryFields() {
        return fieldMapper.queryFields();
    }

    /**
     * 查询所有试题类型
     *
     * @return: 返回试题类型所有内容
     * @Since: 2017-2-13
     * @author: jly
     * */
    @Override
    public List<QuestionType> queryQuestionType() {
        return questionTypeMapper.queryQuestionType();
    }

    /**
     * 查询所有知识点
     *
     * @return: 返回知识点所有内容
     * @Since: 2017-2-13
     * @author: jly
     * */
    @Override
    public List<KnowledgePoint> queryPoint() {
        return knowledgePointMapper.queryPoint();
    }

    /**
     * 查看试题列表具体数据
     *
     * @return: 返回试题列表及相关信息
     * @since: 2017-2-13
     * @author: jly
     * */
    @Override
    public List<Question> questionLists(String creator, int typeId, int kindId, int pointId) {
        return questionMapper.questionLists(creator,typeId,kindId,pointId);
    }

    /**
     *删除试题相关答案
     *
     * @param questionid:试题id
     * @return 返回是否删除成功
     * @since 2017-2-24
     * @author jly
     * */
    @Override
    public boolean delAnswer(int questionid) {
        return questionMapper.delAnswer(questionid);
    }

    /**
     *删除试题
     *
     * @param questionid:试题id
     * @return 返回是否删除成功
     * @since 2017-2-24
     * @author jly
     * */
    @Override
    public boolean delQuestion(int questionid) {
        return questionMapper.delQuestion(questionid);
    }

    /**
     * 加载编辑框信息
     *
     * @param questionid:试题id
     * @return id对应的试题信息
     * @since 2017-2-24
     * @author jly
     * */
    @Override
    public Question loadEdit(int questionid) {
        return questionMapper.loadEdit(questionid);
    }

    /**
     * 编辑试题信息
     *
     * @param fielsId:专业id，pointId:知识点id，answer:正确答案
     * @return: 修改试题信息
     * @since: 2017-2-24
     * @author: jly
     * */
    @Override
    public boolean questionInfo(int fielsId, int pointId, String answer,int questionId) {
        return questionMapper.questionInfo(fielsId,pointId,answer,questionId);
    }

    /**
     * 查看试题详细信息
     *
     * @param questionId 试题id
     * @return: 返回试题详细信息
     * @since: 2017-2-24
     * @author: jly
     * */
    @Override
    public Question questionDetail(Integer questionId) {
        return questionMapper.questionDetail(questionId);
    }

    /**
     * 查看试题列表具体数据(老师登录)
     *
     * @return: 返回试题列表及相关信息
     * @since: 2017-2-13
     * @author: jly
     * */
    @Override
    public List<Question> questionList_teachet(String creator, Integer typeId, Integer kindId, Integer pointId, Long userId) {
        if(typeId == null){
            typeId = 0;
        }
        if(kindId == null){
            kindId = 0;
        }
        if(pointId == null){
            pointId = 0;
        }
        return questionMapper.questionList_teachet(creator,typeId,kindId,pointId,userId);
    }

    /**
     * 添加新知识点
     *
     * @param pointname:知识点名称， pointdesc:知识点描述
     * @since 2017-3-3
     * @author jly
     * */
    @Override
    public boolean addPoint(String pointname, String pointdesc) {
        return questionMapper.addPoint(pointname,pointdesc);
    }

    /**
     * 根据知识点名称查询指点的id
     *
     * @param pointname:知识点名称
     * @since 2017-3-3
     * @author jly
     * */
    @Override
    public int queryPointId(String pointname) {
        return questionMapper.queryPointId(pointname);
    }

    /**
     * 新增试题
     *
     * @param questionName:试题名称， questionDesc：试题描述, kindId:科目, q_type：试题类型
     *         pointId：知识点选择,pointname：知识点新增名称,pointdesc：知识点新增描述
     *         answerA：答案A内容,answerB：答案B内容,answerC：答案C内容,answerD：答案D内容
     *         trueanswer:答案T内容,falseanswer:答案F内容,select1:选择题正确答案,select2:判断题正确答案
     * @since 2017-3-3
     * @author jly
     * */
    @Override
    public boolean addQuestion(String questionName, Long userId, Integer q_type, String select1, Integer kindId, int newpointId, String questionDesc,String level) {
        return questionMapper.addQuestion(questionName,userId,q_type,select1,kindId,newpointId,questionDesc,level);
    }

    /**
     * 添加试题答案（选择题）
     *
     * @param
     * @param newquestionId
     * @since 2017-3-3
     * @author jly
     * */
    @Override
    public boolean addAnswer1(String answer, int newquestionId) {
        return questionMapper.addAnswer1(answer,newquestionId);
    }

    /**
     * 添加试题答案（判断题）
     *
     * @param
     * @param newquestionId
     * @since 2017-3-3
     * @author jly
     * */
    @Override
    public boolean addAnswer2(String answer, int newquestionId) {
        return questionMapper.addAnswer2(answer,newquestionId);
    }

    /**
     * 根据试题点名称查询试题的id
     *
     * @param questionName:试题名称
     * @since 2017-3-3
     * @author jly
     * */
    @Override
    public int queryQuestionId(String questionName) {
        return questionMapper.queryQuestionId(questionName);
    }

    /**
     * 添加科目
     *
     *@param kindname 科目名称,
     * @param kinddesc 科目描述
     * @since 2017-3-14
     * @author jly
     * */
    @Override
    public boolean addKind(String kindname, String kinddesc) {
        return questionMapper.addKind(kindname,kinddesc);
    }

    /**
     * 添加试题类型
     *
     *@param typename 类型名称
     * @since 2017-3-14
     * @author jly
     * */
    @Override
    public boolean addType(String typename) {
        return questionMapper.addType(typename);
    }

    /**
     * 根据科目名称查询科目的id
     *
     * @param kindname:科目
     * @since 2017-3-14
     * @author jly
     * */
    @Override
    public int queryKindId(String kindname) {
        return questionMapper.queryKindId(kindname);
    }


    /**
     * 根据类型名称查询类型的id
     *
     * @param typename:类型名称
     * @since 2017-3-14
     * @author jly
     * */
    @Override
    public int queryTypeId(String typename) {
        return questionMapper.queryTypeId(typename);
    }

    /**
     * 插入选择简单题数目
     *
     * @since 2017-3-15
     * @author jly
     * */
    @Override
    public boolean addXZJD(int fieldxz, int typeId, int xzjd, int level) {
        return strategiesMapper.addXZJD(fieldxz,typeId,xzjd,level);
    }

    /**
     * 插入选择中等题数目
     *
     * @since 2017-3-15
     * @author jly
     * */
    @Override
    public boolean addXZZD(int fieldxz, int typeId, int xzzd, int level) {
        return strategiesMapper.addXZZD(fieldxz,typeId,xzzd,level);
    }

    /**
     * 插入选择难题数目
     *
     * @since 2017-3-15
     * @author jly
     * */
    @Override
    public boolean addXZN(int fieldxz, int typeId, int xzn, int level) {
        return strategiesMapper.addXZN(fieldxz,typeId,xzn,level);
    }

    /**
     * 插入判断简单题数目
     *
     * @since 2017-3-15
     * @author jly
     * */
    @Override
    public boolean addPDJD(int fieldxz, int typeId, int pdjd, int level) {
        return strategiesMapper.addPDJD(fieldxz,typeId,pdjd,level);
    }

    /**
     * 插入判断中等题数目
     *
     * @since 2017-3-15
     * @author jly
     * */
    @Override
    public boolean addPDZD(int fieldxz, int typeId, int pdzd, int level) {
        return strategiesMapper.addPDZD(fieldxz,typeId,pdzd,level);
    }

    /**
     * 插入判断难题数目
     *
     * @since 2017-3-15
     * @author jly
     * */
    @Override
    public boolean addPDN(int fieldxz, int typeId, int pdn, int level) {
        return strategiesMapper.addPDN(fieldxz,typeId,pdn,level);
    }

    /**
     * 插入填空简单题数目
     *
     * @since 2017-3-15
     * @author jly
     * */
    @Override
    public boolean addTKJD(int fieldxz, int typeId, int tkjd, int level) {
        return strategiesMapper.addTKJD(fieldxz,typeId,tkjd,level);
    }

    /**
     * 插入填空中等题数目
     *
     * @since 2017-3-15
     * @author jly
     * */
    @Override
    public boolean addTKZD(int fieldxz, int typeId, int tkzd, int level) {
        return strategiesMapper.addTKZD(fieldxz,typeId,tkzd,level);
    }

    /**
     * 插入填空难题数目
     *
     * @since 2017-3-15
     * @author jly
     * */
    @Override
    public boolean addTKN(int fieldxz, int typeId, int tkn, int level) {
        return strategiesMapper.addTKN(fieldxz,typeId,tkn,level);
    }

    /**
     * 插入主观简单题数目
     *
     * @since 2017-3-15
     * @author jly
     * */
    @Override
    public boolean addZGJD(int fieldxz, Integer typeId, Integer zgjd, int level) {
        return strategiesMapper.addZGJD(fieldxz,typeId,zgjd,level);
    }

    /**
     * 插入主观中等题数目
     *
     * @since 2017-3-15
     * @author jly
     * */
    @Override
    public boolean addZGZD(int fieldxz, Integer typeId, Integer zgzd, int level) {
        return strategiesMapper.addZGZD(fieldxz,typeId,zgzd,level);
    }

    /**
     * 插入主观难题数目
     *
     * @since 2017-3-15
     * @author jly
     * */
    @Override
    public boolean addZGN(int fieldxz, Integer typeId, Integer zgn, int level) {
        return strategiesMapper.addZGN(fieldxz,typeId,zgn,level);
    }

    /**
     * 查询策略表里该科目是否已经存在
     *
     * @param fieldxz--科目id
     * @since 2017-3-15
     * @author jly
     * */
    @Override
    public int queryFieldCount(int fieldxz) {
        return strategiesMapper.queryFieldCount(fieldxz);
    }

    /**
     * 修改选择简单题数目
     *
     * @since 2017-3-15
     * @author jly
     * */
    @Override
    public boolean updataXZJD(int fieldxz, int typeId, int xzjd, int level) {
        return strategiesMapper.updataXZJD(fieldxz,typeId,xzjd,level);
    }

    /**
     * 修改选择中等题数目
     *
     * @since 2017-3-15
     * @author jly
     * */
    @Override
    public boolean updataXZZD(int fieldxz, int typeId, int xzzd, int level) {
        return strategiesMapper.updataXZZD(fieldxz,typeId,xzzd,level);
    }

    /**
     * 修改选择难题数目
     *
     * @since 2017-3-15
     * @author jly
     * */
    @Override
    public boolean updataXZN(int fieldxz, int typeId, int xzn, int level) {
        return strategiesMapper.updataXZN(fieldxz,typeId,xzn,level);
    }

    /**
     * 修改判断简单题数目
     *
     * @since 2017-3-15
     * @author jly
     * */
    @Override
    public boolean updataPDJD(int fieldxz, int typeId, int pdjd, int level) {
        return strategiesMapper.updataPDJD(fieldxz,typeId,pdjd,level);
    }

    /**
     * 修改判断中等题数目
     *
     * @since 2017-3-15
     * @author jly
     * */
    @Override
    public boolean updataPDZD(int fieldxz, int typeId, int pdzd, int level) {
        return strategiesMapper.updataPDZD(fieldxz,typeId,pdzd,level);
    }

    /**
     * 修改判断难题数目
     *
     * @since 2017-3-15
     * @author jly
     * */
    @Override
    public boolean updataPDN(int fieldxz, int typeId, int pdn, int level) {
        return strategiesMapper.updataPDN(fieldxz,typeId,pdn,level);
    }

    /**
     * 修改填空简单题数目
     *
     * @since 2017-3-15
     * @author jly
     * */
    @Override
    public boolean updataTKJD(int fieldxz, int typeId, int tkjd, int level) {
        return strategiesMapper.updataTKJD(fieldxz,typeId,tkjd,level);
    }

    /**
     * 修改填空中等题数目
     *
     * @since 2017-3-15
     * @author jly
     * */
    @Override
    public boolean updataTKZD(int fieldxz, int typeId, int tkzd, int level) {
        return strategiesMapper.updataTKZD(fieldxz,typeId,tkzd,level);
    }

    /**
     * 修改填空难题数目
     *
     * @since 2017-3-15
     * @author jly
     * */
    @Override
    public boolean updataTKN(int fieldxz, int typeId, int tkn, int level) {
        return strategiesMapper.updataTKN(fieldxz,typeId,tkn,level);
    }

    /**
     * 修改主观简单题数目
     *
     * @since 2017-3-15
     * @author jly
     * */
    @Override
    public boolean updataZGJD(int fieldxz, Integer typeId, Integer zgjd, int level) {
        return strategiesMapper.updataZGJD(fieldxz,typeId,zgjd,level);
    }

    /**
     * 修改主观中等题数目
     *
     * @since 2017-3-15
     * @author jly
     * */
    @Override
    public boolean updataZGZD(int fieldxz, Integer typeId, Integer zgzd, int level) {
        return strategiesMapper.updataZGZD(fieldxz,typeId,zgzd,level);
    }

    /**
     * 修改主观难题数目
     *
     * @since 2017-3-15
     * @author jly
     * */
    @Override
    public boolean updataZGN(int fieldxz, Integer typeId, Integer zgn, int level) {
        return strategiesMapper.updataZGN(fieldxz,typeId,zgn,level);
    }

    /**
     * @describe 根据id查询该科目下是否有该类型试题
     * @since 2017-3-16
     * @author jly
     * @param typeId*/
    @Override
    public int queryTypeId2(Integer typeId,Integer fieldId) {
        return strategiesMapper.queryTypeId2(typeId,fieldId);
    }

    /**
     * @describe 根据科目id删除该科目的组卷策略
     * @since 2017-3-17
     * @author jly
     * @param fieldxz*/
    @Override
    public boolean delstrategies(int fieldxz) {
        return questionMapper.delstrategies(fieldxz);
    }

    /**
     * @describe 根据实体名称查询试题是否存在
     * @since 2017-3-17
     * @author jly
     * @param questionName*/
    @Override
    public int queryQuestionCount(String questionName) {
        return questionMapper.queryQuestionCount(questionName);
    }
}
